def file = new File('/home/auerf/Comparison/FULL Proteome/all_pairwise_celllines/all_pairwise_qvalue.csv')
def fileIndex = [:]
def lineIndex = 0
file.eachLine{line->
    if(lineIndex==0){
        def splitted = line.split('\t')
        splitted.eachWithIndex{ele,index->
            fileIndex.put(ele, index)
        }
    }
    lineIndex++
}

def pValIndex = [:]
fileIndex.findAll{it.key.startsWith('p.value.')}.each{pValIndex.put(it.key, it.value)}


pValIndex.each{val,index->
    def outFile = new File('/home/auerf/Comparison/FULL Proteome/all_pairwise_celllines/'+val+'.txt')
    lineIndex = 0
    file.eachLine{line->
        if(lineIndex!=0){
            def splitted = line.split('\t')
            outFile << splitted[1]+'\t'+splitted[index]+'\n'
        }
        lineIndex++
    }
}

def qValIndex = [:]
fileIndex.findAll{it.key.startsWith('q.value.')}.each{qValIndex.put(it.key, it.value)}


qValIndex.each{val,index->
    def outFile = new File('/home/auerf/Comparison/FULL Proteome/all_pairwise_celllines/'+val+'.txt')
    lineIndex = 0
    file.eachLine{line->
        if(lineIndex!=0){
            def splitted = line.split('\t')
            outFile << splitted[1]+'\t'+splitted[index]+'\n'
        }
        lineIndex++
    }
}

def outFile = new File('/home/auerf/Comparison/FULL Proteome/all_pairwise_celllines/genes.txt')
lineIndex = 0
file.eachLine{line->
    if(lineIndex!=0){
        def splitted = line.split('\t')
        outFile << splitted[1]+'\t'+splitted[0]+'\n'
    }
    lineIndex++
}